<template>
  <div class="gmU">
    <headerNav />
    <div class="mindWidth">
      <div class="mincard">
        <span @click="$router.push('/')">首页</span>>
        <span>最新资讯</span>
      </div>
      <div class="filterKeyWord mindWidth">
        <div v-if="!showFen" class="address-content">
          <!-- 省级 -->
          <div class="policyNotice_top_region">
            <div class="policyNotice_top_region_left">
              <span>地区：</span>
            </div>
            <div
              class="policyNotice_top_region_right"
              v-if="provinActive === -1 && judgeWords(regionData, 1)"
              @click="MoreEvent('policyMore')"
            >
              <span ref="policyMore1">更多</span>
              <img ref="policyMore2" src="../../../static/image/triangle.png" />
            </div>
            <ul class="policyNotice_top_region_content" v-if="provinActive > -1">
              <li class="active active1">
                {{ regionData[provinActive].province }}
                <img
                  v-show="isShowError"
                  src="../../../static/image/region_cha.png"
                  @click="provincClearn"
                />
              </li>
            </ul>
            <ul class="policyNotice_top_region_content" v-else ref="policyMore">
              <li :class="provinActive === -1 ? 'active' : ''" @click="onProvince(-1)">全部</li>
              <li
                v-for="(item, index) in regionData"
                :key="index"
                @click="onProvince(index)"
                :class="provinActive === index ? 'active' : ''"
              >{{ item.province }}</li>
            </ul>
          </div>
          <!-- 市级 -->
          <div class="policyNotice_top_region" v-if="provinActive > -1">
            <div class="policyNotice_top_region_left">
              <span></span>
            </div>
            <div
              class="policyNotice_top_region_right"
              v-if="cityActive === -1 &&judgeWords(regionData[provinActive].children, 2)"
              @click="MoreEvent('cityMore')"
            >
              <span ref="cityMore1">更多</span>
              <img ref="cityMore2" src="../../../static/image/triangle.png" />
            </div>
            <ul class="policyNotice_top_region_content" v-if="cityActive > -1">
              <li class="active active1">
                {{ regionData[provinActive].children[cityActive].city }}
                <img
                  v-show="isShowError"
                  src="../../../static/image/region_cha.png"
                  @click="cityClearn"
                />
              </li>
            </ul>
            <ul class="policyNotice_top_region_content" v-else ref="cityMore">
              <li :class="cityActive === -1 ? 'active' : ''" @click="onCity(-1)">全部</li>
              <li
                v-for="(item, index) in regionData[provinActive].children"
                @click="onCity(index)"
                :class="cityActive === index ? 'active' : ''"
                :key="index"
              >{{ item.city }}</li>
            </ul>
          </div>
          <!-- 区级 -->
          <div class="policyNotice_top_region" v-if="cityActive > -1">
            <div class="policyNotice_top_region_left">
              <span></span>
            </div>
            <div
              class="policyNotice_top_region_right"
              @click="MoreEvent('areaMore')"
              v-if="judgeWords(regionData[provinActive].children[cityActive].children,3)"
            >
              <span ref="areaMore1">更多</span>
              <img ref="areaMore2" src="../../../static/image/triangle.png" />
            </div>
            <ul class="policyNotice_top_region_content" ref="areaMore">
              <li :class="areaActive === -1 ? 'active' : ''" @click="onArea(-1)">全部</li>
              <li
                v-for="(item, index) in regionData[provinActive].children[cityActive].children"
                @click="onArea(index)"
                :class="areaActive === index ? 'active' : ''"
                :key="index"
              >{{ item }}</li>
              <!-- <li style="color:#eee" v-if="!regionData[provinActive].children[cityActive].children">暂无地区</li> -->
            </ul>
          </div>
        </div>

        <!-- 分站地区 -->
        <div v-else class="address-content">
          <!-- 省级 -->
          <div class="policyNotice_top_region">
            <div class="policyNotice_top_region_left">
              <span>地区：</span>
            </div>
            <ul class="policyNotice_top_region_content">
              <li class="active active1">{{ province }}</li>
            </ul>
          </div>
          <!-- 市级 -->
          <div class="policyNotice_top_region">
            <div class="policyNotice_top_region_left">
              <span></span>
            </div>
            <ul class="policyNotice_top_region_content">
              <li class="active active1">{{ city }}</li>
            </ul>
          </div>
        </div>

        <div class="detail">
          <div class="detailText">
            <span>关键词 :</span>
            <div class="wirteSize">
              <input type="text" placeholder="请输入关键词" v-model="title" clearable />
              <button class="dominant changeHanld" @click="handleSearch">搜索</button>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="mindWidth wrapper">
      <div class="project_title_bg">
        <span class="name">标题</span>
        <span class="department">发布时间</span>
        <span class="region">发布人</span>
      </div>
    </div>
    <div
      class="mindWidth project_title_content_bg"
      style="min-height: 490px"
      v-loading="loading"
      v-show="notYet"
    >
      <div
        class="project_title_content_list changeHanld"
        @click="handleClick(item.id)"
        v-for="(item, index) in newInformation"
        :key="index"
      >
        <span
          class="name singlerows hovuers"
          v-html="searchHighlight(item.title,'title')"
          :title="item.title"
        ></span>

        <span class="department singlerows">{{ item.createTime || '--' }}</span>
        <span
          class="department singlerows"
          v-html="searchHighlight(item.nickName,'title')"
          :title="item.nickName"
        />
      </div>
    </div>
    <div
      class="mindWidth project_title_content_bg content_imgse"
      style="min-height: 490px; background-color: transparent"
      v-show="!notYet"
    >
      <img src="../../../static/image/noDataBox.png" alt />
      <p>暂无数据</p>
    </div>
    <div class="mindWidth pageList">
      <div class="page">
        <paging ref="paging_zi" v-on:CurrentPage="accept_CurrentValue" :pageNo="Pagevalue" />
      </div>
    </div>
    <footer-nav />
    <navBar />
  </div>
</template>

<script>
import navBar from "../../components/navigation.vue";
import { commonRequest, postRequest } from "../../api/api.js";
import paging from "../../components/paging.vue"; //分页
import { sessionTake } from "../../util/validate";

export default {
  name: "newsInformation",
  components: {
    navBar,
    paging
  },
  head() {
    return {
      title: "最新资讯-比目镜",
      meta: [
        {
          hid: "description",
          name: "description",
          content:
            "比目镜(51bmj.cn)，科技产业政策项目数据平台，提供行业扶持资助补贴政策查询、政府部门最新政策实时智能推送、高新技术企业公示名单查询、高新技术企业项目立项查询、高新技术企业荣誉资质查询、高新技术企业商标专利查询、高新技术企业名单统计、科技项目申报查询、政策项目智能匹配、园区孵化器企业查询、政策扶持项目申报服务"
        },
        {
          hid: "keywords",
          name: "keywords",
          content:
            "比目镜，政策查询，政策智能推送，最新政策，政策解读，政策匹配，政府黄页，企业名单，企业查询，企业项目立项查询，高新技术企业名单查询，高企名单，专利查询，商标查询，专利交易信息发布，高新技术企业认定，科技项目申报"
        }
      ]
    };
  },
  data() {
    return {
      title: "", // 标题
      publisher: "", // 发布人
      Pagevalue: 1,
      loading: true,
      notYet: true, // 是否有数据
      newInformation: [], // 最新资讯列表

      regionData: [],
      provinActive: -1, // 省级选中  -1（全部）
      cityActive: -1, // 市级选中
      areaActive: -1, // 区级选中
      province: "",
      city: "",
      area: "",
      showFen: false
    };
  },
  computed: {
    isShowError() {
      let params = this.$store.state.cityInfo;
      if (params.city === "" && params.province === "") {
        return true;
      } else {
        return false;
      }
    }
  },
  watch: {
    searchItem: {
      deep: true,
      handler(val) {
        this.accept_CurrentValue(1);
        this.getprovinceList(1);
      }
    },
    $route: {
      hanlder(val) {
        if (JSON.stringify() !== "{}") {
          let id = val.query.id;
        }
      }
    }
  },
  mounted() {
    // 分站，没有分站不掉地区列表
    let params = this.$store.state.cityInfo;
    if (params.city && params.province) {
      this.showFen = true;
      this.province = params.province;
      this.city = params.city;
      this.getprovinceList(1);
    } else {
      this.getAreaList();
    }
  },
  methods: {
    judgeWords(data, index) {
      if (data == undefined) {
        return false;
      }
      // 1省级2市级3区级
      if (index == 1) {
        if (data != "") {
          var str = "";
          for (let i = 0; i < data.length; i++) {
            str = str + data[i].province;
          }
          if (str.length * 14 + (12 + 28) * data.length + 68 > 1060) {
            return true;
          } else {
            return false;
          }
        } else {
          return false;
        }
      }
      if (index == 2) {
        if (data != "") {
          var str = "";
          for (let i = 0; i < data.length; i++) {
            str = str + data[i].city;
          }
          if (str.length * 14 + (12 + 28) * data.length + 68 > 1060) {
            return true;
          } else {
            return false;
          }
        } else {
          return false;
        }
      }
      if (index == 3) {
        if (data != "") {
          var str = "";
          for (let i = 0; i < data.length; i++) {
            str = str + data[i];
          }
          if (str.length * 14 + (12 + 28) * data.length + 68 > 1060) {
            return true;
          } else {
            return false;
          }
        } else {
          return false;
        }
      }
    },
    // 跳转资讯详情
    handleClick(id) {
      // window.open(`/newInform?id=${id}`, '_blank');
      window.open(`/newInform/${id}`);
    },

    // 搜索高亮
    searchHighlight(value, property) {
      return this[property]
        ? value.replace(
            new RegExp(this[property], "g"),
            "<em style='color: red;font-style:normal;'>" +
              this[property] +
              "</em>"
          )
        : value;
    },
    // 重置搜索条件
    resetSearchCondition() {
      this.title = "";
      this.publisher = "";
    },
    // 点击搜索按钮
    handleSearch() {
      this.getprovinceList(1);
    },
    // 接受当前选中页数
    accept_CurrentValue(value) {
      this.getprovinceList(value);
    },
    // 资讯列表
    getprovinceList(pageNo) {
      this.Pagevalue = pageNo;
      this.notYet = true;
      this.newInformation = [];
      this.loading = true;

      commonRequest("/api/pms/pmsLatestNews/list", {
        province: this.province,
        city: this.city,
        area: this.area,
        title: this.title,
        nickName: this.publisher,
        pageNo: this.Pagevalue
      }).then(res => {
        this.newInformation = res.records;
        this.$refs.paging_zi.totalValue(res.total);
        this.loading = false;
        if (res.records.length == 0) {
          this.notYet = false;
        }
      });
    },

    // 获取地区数据
    getAreaList() {
      let province = sessionTake("provinceName");
      let city = sessionTake("cityName");
      commonRequest("/api/pms/pmsLatestNews/latestNewsRegionInfo").then(res => {
        this.regionData = res;
        // 判断缓存地区，地区数据列表有没有
        if (province) {
          for (let i = 0; i < res.length; i++) {
            if (res[i].province === province) {
              this.provinActive = i;
              this.province = res[i].province;
              if (city) {
                for (let j = 0; j < res[i].children.length; j++) {
                  if (res[i].children[j].city === city) {
                    this.cityActive = j;
                    this.city = res[i].children[j].city;
                    this.getprovinceList(1);
                    return;
                  } else if (j + 1 == res[i].children.length) {
                    this.cityClearn();
                  }
                }
              } else {
                this.cityClearn();
              }
            } else if (i + 1 == res.length) {
              this.provincClearn();
            }
          }
        } else {
          this.provincClearn();
        }
      });
    },

    // 省级地区切换
    onProvince(value) {
      this.provinActive = value;
      this.province = this.regionData[this.provinActive].province;
      this.getprovinceList(1);
    },
    // 市级地区切换
    onCity(value) {
      this.cityActive = value;
      this.city = this.regionData[this.provinActive].children[
        this.cityActive
      ].city;
      this.getprovinceList(1);
    },
    // 区级地区切换
    onArea(value) {
      this.areaActive = value;
      this.area = this.regionData[this.provinActive].children[
        this.cityActive
      ].children[this.areaActive];
      this.getprovinceList(1);
    },
    // 省级清空
    provincClearn() {
      this.provinActive = -1;
      this.cityActive = -1;
      this.areaActive = -1;
      this.province = "";
      this.city = "";
      this.area = "";
      this.getprovinceList(1);
    },
    // 市级清空
    cityClearn() {
      this.cityActive = -1;
      this.areaActive = -1;
      this.city = "";
      this.area = "";
      this.getprovinceList(1);
    },
    // 更多收起切换
    MoreEvent(value) {
      if (this.$refs[value + "1"].innerHTML == "更多") {
        this.$refs[value + "1"].innerHTML = "收起";
        this.$refs[value].style.maxHeight = "inherit";
        this.$refs[value + "2"].style.transform =
          "translateY(-50%) rotate(180deg)";
      } else {
        this.$refs[value + "1"].innerHTML = "更多";
        this.$refs[value].style.maxHeight = "32px";
        this.$refs[value + "2"].style.transform =
          "translateY(-50%) rotate(0deg)";
      }
    }
  }
};
</script>

<style lang="less" scoped>
.hovuers:hover {
  color: rgb(68, 162, 255);
}

.content_imgse {
  background-color: transparent !important;
  box-shadow: 0 0 black !important;
  overflow: hidden;
  text-align: center;

  img {
    margin: 0 auto;
    margin-top: 138px;
    width: 280px;
  }

  p {
    color: rgb(204, 204, 204);
    font-size: 14px;
    margin-top: 10px;
  }
}

.gmU {
  //
  .mincard {
    span {
      font-size: 14px;
      margin: 0 10px;
      cursor: pointer;
    }
  }

  .filterKeyWord {
    padding: 10px 0;
    background-color: #fff;

    .address-content {
      .policyNotice_top_region {
        padding: 10px 20px;
        overflow: hidden;
        border-bottom: 1px solid #eee;
        overflow: hidden;
        position: relative;
      }

      .policyNotice_top_department {
        padding: 10px 20px;
        border-bottom: 1px solid #eee;
        padding-bottom: 12px;

        .policyNotice_top_region_distance {
          margin-top: 0;
        }
      }

      .policyNotice_top_region_left {
        float: left;

        span {
          font-size: 14px;
          padding: 2px 6px;
          color: #333;
        }
      }

      .policyNotice_top_region_right {
        position: absolute;
        right: 20px;
        top: 14px;
        width: 40px;
        cursor: pointer;

        span {
          font-size: 14px;
          color: rgb(68, 162, 255);
        }

        img {
          position: absolute;
          right: 0px;
          top: 50%;
          transform: translateY(-50%) rotate(0);
          width: 8px;
        }
      }

      .policyNotice_top_region_content {
        margin-left: 60px;
        overflow: hidden;
        max-height: 32px;
        margin-right: 40px;

        li {
          float: left;
          font-size: 14px;
          padding: 2px 6px;
          color: #333;
          margin: 3px 14px;
          cursor: pointer;
          line-height: 22px;
          &:hover {
            background-color: #44a2ff;
            color: #fff;
            border-radius: 4px;
          }
        }

        .active {
          background-color: #44a2ff;
          color: #fff;
          position: relative;
          overflow: hidden;
          border-radius: 4px;

          img {
            width: 16px;
            position: absolute;
            right: -2px;
            top: -2px;
          }
        }

        .active1 {
          padding-right: 16px;
        }
      }

      .policyNotice_top_search {
        padding: 18px 20px;

        .policyNotice_top_region_distance {
          margin-top: 0;

          span {
            line-height: 32px;
          }
        }

        .policyNotice_top_search_content {
          margin-left: 85px;
          margin-right: 90px;
          overflow: hidden;
          input {
            float: left;
            display: inline-block;
            width: 240px;
            height: 32px;
            background: #ffffff;
            border: 1px solid #daeaf5;
            border-radius: 4px 0px 0px 4px;
            box-sizing: border-box;
            padding-left: 12px;
            &::-webkit-input-placeholder {
              color: #aaa;
            }
          }

          span {
            float: left;
            display: inline-block;
            box-sizing: border-box;
            width: 60px;
            height: 32px;
            line-height: 30px;
            background: #44a2ff;
            border-radius: 0px 4px 4px 0px;
            text-align: center;
            margin-left: -1px;
            color: #fff;
            cursor: pointer;
          }
        }

        .policyNotice_top_search_right {
          float: right;
          width: 80px;
          height: 32px;
          line-height: 30px;
          background: #44a2ff;
          border-radius: 4px;
          text-align: center;
          color: #fff;
          cursor: pointer;
        }
      }
    }

    .region_H {
      .area_name {
        border-bottom: 1px solid rgb(238, 238, 238);
      }

      .area_content {
        position: relative;
        display: flex;
        align-content: center;
        max-height: 50px;
        overflow: hidden;
        padding: 5px 0;
        // flex-wrap: wrap;
        // align-items: center;
        &.active {
          max-height: 1000px;
          align-items: flex-start;
        }

        .allProvince_item {
          display: flex;
          flex: 1;
          max-height: 100px;
        }

        .more {
          position: absolute;
          top: 12px;
          right: 21px;
          color: #44a2ff;
          font-size: 14px;

          &.active {
            color: #44a2ff;
          }
        }

        .all {
          position: relative;
          display: flex;
          align-items: center;
          justify-content: center;
          height: 30px;
          padding: 0px 10px;
          border-radius: 4px;
          font-size: 14px;
          margin-left: 2px;

          &.active {
            background-color: #44a2ff;
            color: #fff;

            img {
              width: 16px;
              position: absolute;
              top: -2px;
              right: -2px;
            }
          }
        }

        .area_content_L {
          width: 135px;
          padding-top: 3px;
          padding-left: 20px;

          span {
            font-size: 14px;
          }
        }

        .areaItem {
          display: flex;
          flex-wrap: wrap;
          width: 930px;
        }

        .area_content_R {
          display: flex;
          border-radius: 6px;
          height: 35px;

          span {
            font-size: 14px;
            display: flex;
            margin: 0 8px;
            align-items: center;
            border-radius: 4px;
            padding: 0px 10px;
            color: rgb(51, 51, 51);

            &:hover {
              background-color: #44a2ff;
              border-radius: 4px;
              color: #fff;
            }
          }

          &.active {
            background-color: #44a2ff;
            color: #fff;

            span {
              color: #fff;
            }
          }
        }
      }

      .section_item {
        display: flex;
        padding: 15px 0;
        border-bottom: rgb(238, 238, 238) 1px solid;

        .section_title {
          margin-left: 20px;
          width: 96px;
          font-size: 14px;
        }

        .section_all {
          width: 50px;
          height: 30px;
          text-align: center;
          margin: 0 20px;
          line-height: 30px;
          font-size: 14px;

          &.active {
            border-radius: 4px;
            background-color: #44a2ff;
            color: #fff;
          }
        }

        .section_centent_item {
          display: flex;
          overflow: hidden;
          max-height: 30px;
          flex-wrap: wrap;
          flex: 1;

          &.item_minHeight {
            min-height: 30px;
            max-height: 7000px;
          }

          .item {
            font-size: 14px;
            margin-left: 10px;
            padding: 6px 8px;
            color: rgb(51, 51, 51);
            border-radius: 4px;
            height: 30px;

            &:hover {
              background-color: #44a2ff;
              border-radius: 4px;
              color: #fff;
            }

            &.active {
              border-radius: 6px;
              background-color: #44a2ff;
              color: #fff;
            }
          }
        }

        .more {
          font-size: 14px;
          color: #44a2ff;
          margin-right: 20px;
        }
      }
    }
  }

  .detail {
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: space-between;

    .detailText {
      display: flex;
      align-items: center;

      span {
        width: 116px;
        padding-left: 20px;
        font-size: 14px;
        margin-right: 20px;
      }

      .wirteSize {
        display: flex;
        height: 32px;
        width: 300px;
        font-size: 0;

        input {
          border-radius: 4px 0 0 4px;
          width: 240px;
          border: 1px solid #44a2ff;
          height: 100%;
          display: block;
          padding-left: 10px;
          font-size: 14px;
        }

        button {
          border-radius: 0px 4px 4px 0px;
          float: left;
          width: 60px;
          height: 100%;
          padding: 0;
          margin-left: -1px;
        }
      }
    }

    .detailAtlas {
      width: 80px;
      height: 32px;
      line-height: 30px;
      background: rgb(68, 162, 255);
      border-radius: 4px;
      text-align: center;
      color: rgb(255, 255, 255);
      cursor: pointer;
      margin-right: 20px;
    }
  }

  .project_title_bg {
    height: 50px;
    display: flex;
    align-items: center;
    padding-left: 10px;

    span {
      margin: 0 10px;
      color: #fff;
      font-size: 14px;
    }

    .name {
      flex: 3;
    }

    .department {
      flex: 1;
    }

    .region {
      flex: 1;
    }

    // .date {
    //   flex: 2;
    // }

    // .condition {
    //   flex: 2;
    // }
  }

  .project_title_content_bg {
    background-color: #fff;
    margin: 20px auto;
  }

  .project_title_content_list {
    margin: 10px auto;
    height: 40px;
    display: flex;
    align-items: center;

    span {
      margin: 0 10px;
      font-size: 14px;
    }

    .name {
      flex: 3;
    }

    .department {
      flex: 1;
    }

    .region {
      flex: 1;
    }

    .date {
      flex: 2;
    }

    .condition {
      flex: 2;
    }
  }

  .pageList {
    height: 100px;
    display: flex;
    flex-direction: row-reverse;
  }

  .page {
    display: flex;
    float: right;
    align-items: center;

    .pageNum {
      font-size: 14px;
      margin-right: 20px;

      span {
        color: #44a2ff;
        margin: 0 5px;
      }
    }

    .tempPage {
      margin-left: 10px;

      input {
        margin: 0 5px;
        text-align: center;
        width: 30px;
        height: 30px;
        border: 1px solid #ccc;
      }
    }
  }
}
</style>
